﻿/*
 * Cratos Example - Data Object
 * Cratos Example Person class
 * 
 * Copyright (c) 2011 Draco
 * 
 * This file is part of Cratos.
 * 
 * Cratos is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Cratos is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Cratos.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *       .==.        .==.
 *      //'^\\      //^'\\
 *     // ^ ^\(\__/)/^ ^^\\
 *    //^ ^^ ^/6  6\ ^^ ^ \\
 *   //^ ^^ ^/( .. )\^ ^ ^ \\
 *  // ^^ ^/\| V""V|/\^ ^ ^ \\
 * //^^/\/ /  '~~'  \ \/\^ ^ \\
 *  ------------------------------------
 *  HERE BE DRAGONS
 *  
 *  Johan Dercksen - johan@draco.co.za
 */
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;

using Cratos.Tools.General;
using Cratos.Tools.DataObject;

namespace Cratos.Example.DataObject
{
	/// <summary>
	/// Person Data Object class
	/// </summary>
	[DOCratos("Person")]
	[Serializable]
	[DOCratosAction(DOCratosAction.Retrieve, DOCratosActionType.StoredProcedure, true, "spPerson_Retrieve")]
	[DOCratosAction(DOCratosAction.Create, DOCratosActionType.StoredProcedure, true, "spPerson_Create")]
	[DOCratosAction(DOCratosAction.Update, DOCratosActionType.StoredProcedure, false, "spPerson_Update")]
	[DOCratosAction(DOCratosAction.Delete, DOCratosActionType.StoredProcedure, false, "spPerson_Delete")]
	public class DOPerson : DOCratos, IDOCratos
	{
		#region Class Constant declarations
		private const string DBIdColumn        = "Person_ID";
		private const string DBTitleIdColumn   = "Title_ID";
		private const string DBInitialsColumn  = "Person_Initials";
		private const string DBFirstnameColumn = "Person_Firstname";
		private const string DBSurnameColumn   = "Person_Surname";
		private const string DBIsActiveColumn  = "Person_IsActive";
		#endregion

		#region Class Event declarations
		#endregion

		#region Class Variable declarations
		#region Data Object Variables
		private long		m_Id;
		private long		m_TitleId;
		private string	m_Initials;
		private string	m_Firstname;
		private string	m_Surname;
		private bool		m_IsActive;
		#endregion

		#region Embedded Object Variables
		private DOTitle	m_Title;
		#endregion
		#endregion

		#region Class Constructors & Destructors
		/// <summary>
		/// Class Constructor
		/// </summary>
		public DOPerson() : base()
		{
			// Set the relevant CRUD Action indicators
			this.CanCreate		= true;
			this.CanRetrieve	= true;
			this.CanUpdate		= true;
			this.CanDelete		= true;
		}
		#endregion

		#region Class Properties
		#region Data Object Properties
		/// <summary>
		/// Person ID
		/// </summary>
		[DOCratosColumn("ID", "Id", DbType.Int64, DOPerson.DBIdColumn, 0, IsKey = true)]
		[DOCratosActionColumn(DOCratosAction.Retrieve, true)]
		[DOCratosActionColumn(DOCratosAction.Update, true)]
		[DOCratosActionColumn(DOCratosAction.Delete, true)]
		public long Id
		{
			get { return (this.m_Id); }
			set { this.m_Id = value; this.NotifyPropertyChanged("Id"); this.IsChanged = true; }
		}

		/// <summary>
		/// Title ID
		/// </summary>
		[DOCratosColumn("Title ID", "TitleId", DbType.Int64, DOPerson.DBTitleIdColumn, 0)]
		[DOCratosActionColumn(DOCratosAction.Create, true)]
		[DOCratosActionColumn(DOCratosAction.Update, true)]
		public long TitleId
		{
			get { return (this.m_TitleId); }
			set { this.m_TitleId = value; this.NotifyPropertyChanged("TitleId"); this.IsChanged = true; }
		}

		/// <summary>
		/// Person Initials
		/// </summary>
		[DOCratosColumn("Initials", "Initials", DbType.String, DOPerson.DBInitialsColumn, "")]
		[DOCratosActionColumn(DOCratosAction.Create, true)]
		[DOCratosActionColumn(DOCratosAction.Update, true)]
		public string Initials
		{
			get { return (this.m_Initials); }
			set { this.m_Initials = value; this.NotifyPropertyChanged("Initials"); this.IsChanged = true; }
		}

		/// <summary>
		/// Person First Name(s)
		/// </summary>
		[DOCratosColumn("Firstname", "Firstname", DbType.String, DOPerson.DBFirstnameColumn, "")]
		[DOCratosActionColumn(DOCratosAction.Create, true)]
		[DOCratosActionColumn(DOCratosAction.Update, true)]
		public string Firstname
		{
			get { return (this.m_Firstname); }
			set { this.m_Firstname = value; this.NotifyPropertyChanged("Firstname"); this.IsChanged = true; }
		}

		/// <summary>
		/// Person Surname
		/// </summary>
		[DOCratosColumn("Surname", "Surname", DbType.String, DOPerson.DBSurnameColumn, "")]
		[DOCratosActionColumn(DOCratosAction.Create, true)]
		[DOCratosActionColumn(DOCratosAction.Update, true)]
		public string Surname
		{
			get { return (this.m_Surname); }
			set { this.m_Surname = value; this.NotifyPropertyChanged("Surname"); this.IsChanged = true; }
		}

		/// <summary>
		/// Person Active indicator
		/// </summary>
		[DOCratosColumn("Is Active", "IsActive", DbType.Boolean, DOPerson.DBIsActiveColumn, true)]
		public bool IsActive
		{
			get { return (this.m_IsActive); }
			set { this.m_IsActive = value; this.NotifyPropertyChanged("IsActive"); this.IsChanged = true; }
		}
		#endregion

		#region Embedded Object Properties
		/// <summary>
		/// Title
		/// </summary>
		[DOCratosEmbedded("Title", "Title", true)]
		[DOCratosEmbeddedKey("TitleId", "Id", true)]
		public DOTitle Title
		{
			get
			{
				// Determine if we have an object
				if (this.m_Title == null) { this.m_Title = new DOTitle(); }

				// Load the embedded object if required
				if (!this.IsLoading) { this.LoadEmbedded("Title", this.m_Title); }

				// Return to calling method
				return(this.m_Title);
			}
			set { this.m_Title = value; this.NotifyPropertyChanged("Title"); }
		}
		#endregion
		#endregion

		#region Class Methods
		/// <summary>
		/// Create Object from a Serialized object
		/// </summary>
		/// <param name="objectStream">A byte array representing the serialized object</param>
		/// <returns>
		/// The recreated object
		/// </returns>
		public override IDOCratos CreateObjectFromStream(byte[] objectStream)
		{
			// Serialize the data
			return ((DOPerson) DOCratosGlobal.BinDeserialize(objectStream));
		}
		#endregion

		#region Class Support Methods
		#endregion
	}
}
